package forces;

import masses.Mass;
import simulations.Simulation;


/**
 * This class represents a wall repulsion force that repels masses from a given
 * wall.
 * 
 * @author Jenni Mercado
 */

public class WallRepulsion extends Force {

    private int myExpVal;
    private int myWallID;
    private double myMagnitude;
    private Simulation mySimulation;

    public WallRepulsion (int id, double magnitude, int expVal,
            Simulation simulation) {
        super(idToDirection(id), magnitude);
        myMagnitude = magnitude;
        myWallID = id;
        // negate the argument because we are following an inverse exponent law
        myExpVal = -expVal;
        // need a reference to the simulation to determine bounds
        mySimulation = simulation;
    }

    /** default constructor for when a wall is not specified in file */
    public WallRepulsion (int id, Simulation simulation) {
        myMagnitude = 1;
        myExpVal = 2;
        mySimulation = simulation;
    }

    public double getRightBound () {
        return mySimulation.getSize().getWidth();
    }

    private double getLowerBound () {
        return mySimulation.getSize().getHeight();
    }

    /**
     * helper method for converting a wall ID into a direction
     * 
     * @param id
     * @return
     */
    private static double idToDirection (int id) {
        switch (id) {
            case 1:
                return 90;
            case 2:
                return 180;
            case 3:
                return 270;
            case 4:
                return 0;
            default:
                // good practice
        }
        return 0; // should never get here but we provide a default value
    }

    @Override
    public void update (Mass mass) {
        double distance = 0;
        switch (myWallID) {
            case 1:
                distance = mass.getCenter().getY();
            case 2:
                distance = getRightBound() - mass.getCenter().getX();
            case 3:
                distance = getLowerBound() - mass.getCenter().getY();
            case 4:
                distance = mass.getCenter().getX();
            default:
                // good style
        }
        // scale magnitude by the inverse exponent law
        double scale = Math.pow(distance, myExpVal);
        this.setMagnitude(myMagnitude * scale);
    }

}
